<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/6/17
 * Time: 16:41
 */
namespace app\job;

use think\queue\Job;
use think\Db;

class Wenjuan
{
    /**
     * fire方法是消息队列默认调用的方法
     * @param Job            $job      当前的任务对象
     * @param array|mixed    $data     发布任务时自定义的数据
     */
    public function fire(Job $job, $data)
    {
        //....这里执行具体的任务
        if($this->jobDone($data))
        {
            print("消费成功_Wenjuan".$data."_".date('Y/m/d H:i:s'));
            $job->delete();
            
        }else{
            $job->release(3); //$delay为延迟时间
        }

        if ($job->attempts() > 3) {
            //通过这个方法可以检查这个任务已经重试了几次了

        }

        //如果任务执行成功后 记得删除任务，不然这个任务会重复执行，直到达到最大重试次数后失败后，执行failed方法
        // $job->delete();

        // 也可以重新发布这个任务
        // $job->release($delay); //$delay为延迟时间

    }

    public function failed($data)
    {

        // ...任务达到最大重试次数后，失败了
    }

    public function jobDone($data)
    {
        //print("<info>Wenjuan".$data." Job is Done status!"."</info> \n");
        print("开始消费_Wenjuan".$data."_".date('Y/m/d H:i:s'));
        try{
            $a_id = $data;
            $answer = db::name('answer')->field('user_id,s_id,info')->where('a_id',$a_id)->find();
            $answer_info = $answer['info'];
            $answer_arr = json_decode($answer_info,true);
            foreach ($answer_arr as $k=>$v){
                $temp = explode('_',$k);
                unset($answer_arr[$k]);
                $answer_arr[$temp[0]] = $v;
            }

            $result_data = [];

            //---基础版---
            $info1 = [];//七、专利及知识产权维度
            $score_jc['1.1'] = getLevelScoreOne($answer_arr[28],58,4);
            $score_word['1.1'] = getBaseComparison($answer_arr[28],58,'1.1');
            array_push($info1,['1.1 授权专利、软著、商标、电路布图总数',$score_word['1.1']['one'],$score_word['1.1']['two'],$score_word['1.1']['three']]);

            $score_jc['1.2'] = getLevelScoreOne($answer_arr[32],33,5);
            $score_word['1.2'] = getBaseComparison($answer_arr[32],33,'1.2');
            array_push($info1,['1.2 已授权发明专利总数',$score_word['1.2']['one'],$score_word['1.2']['two'],$score_word['1.2']['three']]);

            $score_jc['1.3'] = getLevelScoreOne($answer_arr[34],5,5);
            $score_word['1.3'] = getBaseComparison($answer_arr[34],33,'1.3');
            array_push($info1,['1.3 已授权自主研发核心发明专利总数',$score_word['1.3']['one'],$score_word['1.3']['two'],$score_word['1.3']['three']]);

            $score_jc['1.4-7'] = 3.7;
            array_push($info1,['1.4 专利质量初审情况','有提升空间，争取达到打谁、防谁、和谁的专利质量六字方针','-70.0%','增量专利咨询, 提高营收与专利关联度']);
            array_push($info1,['1.5 专利布局初审情况','有待提高，争取达到保护自身技术，抵御外来诉讼风险的目标','-83.0%','增量专利咨询, 提高营收与专利关联度']);
            array_push($info1,['1.6 专利保护初审情况','有提升空间，在保证专利质量的前提下，要有布局和数量支撑','-53.0%','增量专利咨询, 提高营收与专利关联度']);
            array_push($info1,['1.7 专利侵权风险及规避初审情况','需重点关注，建议完善侵权预警分析，制定实施风险规避方案','-37.0%','二饼图方案及亮剑计划, 专利无效分析']);
            $result_data[1] = ['title'=>'一、专利及知识产权维度','info'=>$info1];

            $info2 = [];//八、研发维度
            $score_jc['2.1'] = getLevelScoreOne($answer_arr[46],100,7);
            $score_word['2.1'] = getBaseComparison($answer_arr[46],109,'2.1');
            array_push($info2,['2.1 研发人员总数',$score_word['2.1']['one'],$score_word['2.1']['two'],$score_word['2.1']['three']]);

            $score_jc['2.2'] = getLevelScoreOne($answer_arr[78],2,4);
            $score_word['2.2'] = getBaseComparison($answer_arr[78],2,'2.2');
            array_push($info2,['2.2 顶级研发人员总数',$score_word['2.2']['one'],$score_word['2.2']['two'],$score_word['2.2']['three']]);

            if($answer_arr[24] > 0){
                $temp = $answer_arr[46]/$answer_arr[24];
            }else{
                $temp = 0;
            }
            $temp_jisuanbishu = round($temp/0.22*8.4,2);
            if($temp < 0.1){
                $score_jc["2.3"] = getLevelScoreOne($temp,0.22,3);
            }else if($temp_jisuanbishu >= 8.4){
                $score_jc["2.3"] = 8.4;
            }else if($temp_jisuanbishu <= 8.4){
                $score_jc["2.3"] = $temp_jisuanbishu;
            }
            $score_word['2.3'] = getBaseComparison($temp,0.22,'2.3');
            $word_score_diffen32 = ($temp/0.22)-1;
            $word_score_diffen_text = "";
            if ($word_score_diffen32 > 0.01) {
                $word_score_diffen_text = '高于行业参考值';
            } else if ($word_score_diffen32 == 0.01) {
                $word_score_diffen_text = '相似于行业参考值';
            } else {
                if ($word_score_diffen32 == 0) {
                    $word_score_diffen_text = '与参考值差距较大，希望2年内达到21%的研发人员占比';
                } else {
                    $word_score_diffen_text = '低于行业参考值';
                }
            }
            array_push($info2,['2.3 研发人员占比',$word_score_diffen_text,$score_word['2.3']['two'],$score_word['2.3']['three']]);
            //2.4研发设施
            $word_2_4_diffen_text = $word_2_4_diffen_hundren=$word_2_4_diffen_text_one = "";
            if ($answer_arr[75] == 9 && $answer_arr[76] == 2) {//"9.都不是"
                $score_jc["2.4"] = 0;
                $word_2_4_diffen_text = "没有，与90%的同业申报企业情况相似";
                $word_2_4_diffen_hundren = "-10%";
                $word_2_4_diffen_text_one = "按“四个一流”研发体系要求补足短板";
            } else {
                $score_jc["2.4"] = 3.2;
                $word_2_4_diffen_text = "有，优于70%的同业申报企业";
                $word_2_4_diffen_hundren = "90%";
                $word_2_4_diffen_text_one = "已经满足目前要求";
            }
            array_push($info2,['2.4 是否拥有或掌握四个一流的研发体系',$word_2_4_diffen_text,$word_2_4_diffen_hundren,$word_2_4_diffen_text_one]);
            //2.5研发设施
            $score_jc["2.5"] = getLevelScoreOne($answer_arr[47]+$answer_arr[48]+$answer_arr[49],10000,8.8);
            $score_word['2.5'] = getBaseComparison($answer_arr[47]+$answer_arr[48]+$answer_arr[49],10000,'2.5');
            array_push($info2,['2.5 研发费用',$score_word['2.5']['one'],$score_word['2.5']['two'],$score_word['2.5']['three']]);
            //2.6研发费用占比
            $temp = (($answer_arr[47]/$answer_arr[50]*0.5)+($answer_arr[48]/$answer_arr[51]*0.3)+($answer_arr[49]/$answer_arr[52]*0.2))/3;
            $score_jc["2.6"] = getLevelScoreOne($temp,0.125,10);
            $score_word['2.6'] = getBaseComparison($temp,0.125,'2.6');
            array_push($info2,['2.6 研发费用占比',$score_word['2.6']['one'],$score_word['2.6']['two'],$score_word['2.6']['three']]);
            $result_data[2] = ['title'=>'二、研发维度','info'=>$info2];

            $info3 = [];//九、行政管理维度
            //3.1竞业限制和竞业禁止
            $word_3_1_diffen_text = $word_3_1_diffen_hundren = $word_3_1_diffen_text_one = '';
            if ($answer_arr[39] == 1) { //1:yes、2:no
                $score_jc["3.1"] = 2;
                $word_3_1_diffen_text = "有，但是要仔细审核相关文件，才可以得出结论";
                $word_3_1_diffen_hundren = "63%";
                $word_3_1_diffen_text_one = "已经满足目前要求";
            } else {
                $word_3_1_diffen_text = "无，与37%的同业申报企业情况相似";
                $word_3_1_diffen_hundren = "-37%";
                $word_3_1_diffen_text_one = "现有资产保密流程, 补足竞业相关协议";
            }
            array_push($info3, ['3.1 竞业限制和竞业禁止', $word_3_1_diffen_text, $word_3_1_diffen_hundren, $word_3_1_diffen_text_one]);
            $result_data[3] = ['title' => '三、行政管理维度', 'info' => $info3];

            $info4 = [];//十、技术维度
            //4.1现有技术先进性复杂性
            $score_jc["4.1"] = 1;
            array_push($info4,['4.1 现有技术先进性和复杂性','缺乏先进性和复杂性，与83%的同业申报企业情况相似','-83%','以核心专利布局占比等维度, 分析说明']);
            //4.2现有技术国内红海或蓝海
            $word_4_2_diffen_text = $word_4_2_diffen_hundren = $word_4_2_diffen_text_one = "";
            if ($answer_arr[37] == 7) {//5个以上
                //红海
                $score_jc["4.2"] = 1;
                $word_4_2_diffen_text = "红海领域，与73%的同业申报企业情况相似";
                $word_4_2_diffen_hundren = "-27%";
                $word_4_2_diffen_text_one = "侵权预警和无效对方专利分析，及布局攻击型专利";
            } else {
                //蓝海
                $score_jc["4.2"] = 3;
                $word_4_2_diffen_text = "蓝海领域，与27%的同业申报企业情况相似";
                $word_4_2_diffen_hundren = "73%";
                $word_4_2_diffen_text_one = "已经满足目前要求";
            }
            array_push($info4, ['4.2 产业领域是否红海还是蓝海', $word_4_2_diffen_text, $word_4_2_diffen_hundren, $word_4_2_diffen_text_one]);
            $result_data[4] = ['title' => '四、技术维度', 'info' => $info4];

            $info5 = [];//十一、国内竞争维度
            //5.1是否获得国家重大立项
            $word_5_1_diffen_text = $word_5_1_diffen_hundren = $word_5_1_diffen_text_one = "";
            if ($answer_arr[66] == 8) {//以上都无
                $score_jc["5.1"] = 0;
                $word_5_1_diffen_text = "不是，与73%的同业申报企业情况相似";
                $word_5_1_diffen_hundren = "-73%";
                $word_5_1_diffen_text_one = "研发外协, 以前瞻专利布局做技术预测";
            } else {
                $score_jc["5.1"] = 5.1;
                $word_5_1_diffen_text = "是，优于65%的同业申报企业";
                $word_5_1_diffen_hundren = "27%";
                $word_5_1_diffen_text_one = "已经满足目前要求";
            }
            array_push($info5, ['5.1 是否获得国家重大立项', $word_5_1_diffen_text, $word_5_1_diffen_hundren, $word_5_1_diffen_text_one]);
            //5.2是否获得最高科技奖
            $word_5_2_diffen_text = $word_5_2_diffen_hundren = $word_5_2_diffen_text_one = "";
            if ($answer_arr[68] == 11) {//"无"
                $score_jc["5.2"] = 0;
                $word_5_2_diffen_text = "不是，与80%的同业申报企业情况相似";
                $word_5_2_diffen_hundren = "-80%";
                $word_5_2_diffen_text_one = "研发外协, 以前瞻专利布局做技术预测";
            } else {
                $score_jc["5.2"] = 2.3;
                $word_5_2_diffen_text = "是，优于80%的同业申报企业";
                $word_5_2_diffen_hundren = "20%";
                $word_5_2_diffen_text_one = "已经满足目前要求";
            }
            array_push($info5, ['5.2 是否获得最高科技奖', $word_5_2_diffen_text, $word_5_2_diffen_hundren, $word_5_2_diffen_text_one]);
            //5.3是否参与制定国家行业标准
            $word_5_3_diffen_text = $word_5_3_diffen_hundren = $word_5_3_diffen_text_one = "";
            if ($answer_arr[67] == 6) {//"没有参与过"
                $score_jc["5.3"] = 0;
                $word_5_3_diffen_text = "不是，与75%的同业申报企业情况相似";
                $word_5_3_diffen_hundren = "-75%";
                $word_5_3_diffen_text_one = "研发外协, 以前瞻专利布局做技术预测";
            } else {
                $score_jc["5.3"] = 3.1;
                $word_5_3_diffen_text = "是，优于75%的同业申报企业";
                $word_5_3_diffen_hundren = "25%";
                $word_5_3_diffen_text_one = "已经满足目前要求";
            }
            array_push($info5, ['5.3 是否参与制定国家行业标准', $word_5_3_diffen_text, $word_5_3_diffen_hundren, $word_5_3_diffen_text_one]);
            //5.4是否是国内行业的第一梯队
            $word_5_4_diffen_text = $word_5_4_diffen_hundren = $word_5_4_diffen_text_one = "";
            if ($answer_arr[70] == 1) { //1yes2no
                $score_jc["5.4"] = 4.2;
                $word_5_4_diffen_text = "是，优于70%的同业申报企业";
                $word_5_4_diffen_hundren = "30%";
                $word_5_4_diffen_text_one = "已经满足目前要求";
            } else {
                $word_5_4_diffen_text = "不是，与70%的同业申报企业情况相似";
                $word_5_4_diffen_hundren = "-70%";
                $word_5_4_diffen_text_one = "研发外协, 以前瞻专利布局做技术预测";
            }
            array_push($info5, ['5.4 是否是国内行业的第一梯队', $word_5_4_diffen_text, $word_5_4_diffen_hundren, $word_5_4_diffen_text_one]);
            $result_data[5] = ['title' => '五、国内竞争维度', 'info' => $info5];

            $info6 = [];//十二、国际竞争维度
            //6.1是否是国内行业的第一梯队
            $word_6_1_diffen_text = $word_6_1_diffen_hundren = $word_6_1_diffen_text_one = "";
            if ($answer_arr[71] == 1) {//1yes2no
                $score_jc["6.1"] = 5.7;
                $word_6_1_diffen_text = "是，优于60%的同业申报企业";
                $word_6_1_diffen_hundren = "40%";
                $word_6_1_diffen_text_one = "已经满足目前要求";
            } else {
                $word_6_1_diffen_text = "不是，与60%的同业申报企业情况相似";
                $word_6_1_diffen_hundren = "-60%";
                $word_6_1_diffen_text_one = "研发外协, 以前瞻专利布局做技术预测";
            }
            array_push($info6, ['6.1 是否是行业全球龙头企业的供应商', $word_6_1_diffen_text, $word_6_1_diffen_hundren, $word_6_1_diffen_text_one]);
            //6.2是否是国内行业的第一梯队
            $word_6_2_diffen_text = $word_6_2_diffen_hundren = $word_6_2_diffen_text_one = "";
            if ($answer_arr[72] == 1) {//1yes2no
                $score_jc["6.2"] = 7.2;
                $word_6_2_diffen_text = "是，优于77%的同业申报企业";
                $word_6_2_diffen_hundren = "23%";
                $word_6_2_diffen_text_one = "已经满足目前要求";
            } else {
                $word_6_2_diffen_text = "不是，与77%的同业申报企业情况相似";
                $word_6_2_diffen_hundren = "-77%";
                $word_6_2_diffen_text_one = "研发外协, 以前瞻专利布局做技术预测";
            }
            array_push($info6,['6.2 是否取代西方技术或产品', $word_6_2_diffen_text, $word_6_2_diffen_hundren, $word_6_2_diffen_text_one]);
            $result_data[6] = ['title' => '六、国际竞争维度', 'info' => $info6];


            $souce_total_base = array_sum($score_jc); //基础版得分80.12
            //$souce_total_cx = array_sum($score_cx); //创新管理得分72.34
            // dump($souce_total_base);
            // dump($souce_total_cx);

            //基础版计算分数
            $temp_score_onestart = 0;
            if ($souce_total_base >= 35 && $souce_total_base <= 45) {
                $temp_score_onestart = 10;
            }

            $temp_score_twoti = 0;
            if ($souce_total_base < 45) {
                if ($answer_arr[50] >= 8000) {
                    $temp_score_twoti = 15;
                } else if ($answer_arr[50] >= 6000) {
                    $temp_score_twoti = 10;
                } else if ($answer_arr[50] >= 4000) {
                    $temp_score_twoti = 7.5;
                } else if ($answer_arr[50] >= 2000) {
                    $temp_score_twoti = 5;
                }
            } else {
                if ($answer_arr[50] >= 20000) {
                    $temp_score_twoti = 15;
                } else if ($answer_arr[50] >= 10000) {
                    $temp_score_twoti = 11.25;
                } else if ($answer_arr[50] >= 5000) {
                    $temp_score_twoti = 7.5;
                } else if ($answer_arr[50] >= 2000) {
                    $temp_score_twoti = 3.75;
                }
            }
            $temp_score_threeti = 0;
            if ($souce_total_base < 45) {
                $profit = $answer_arr[60] + $answer_arr[59] + $answer_arr[58];
                if ($profit >= 2000) {
                    $temp_score_threeti = 15;
                } else if ($profit >= 1000) {
                    $temp_score_threeti = 10;
                } else if ($profit >= 500) {
                    $temp_score_threeti = 5;
                }
            }
            $temp_score_fourti = 0;
            if ($souce_total_base < 45) {
                $rd_cost = $answer_arr[49] + $answer_arr[48] + $answer_arr[47];
                if ($rd_cost >= 3000) {
                    $temp_score_fourti = 15;
                } else if ($rd_cost >= 2000) {
                    $temp_score_fourti = 10;
                } else if ($rd_cost > 1000) {
                    $temp_score_fourti = 5;
                }
            }
            $score_max_score = max([$temp_score_onestart,$temp_score_twoti, $temp_score_threeti, $temp_score_fourti]);
            $score_sum_base_one = 0;
            if ($answer_arr[49] + $answer_arr[48] + $answer_arr[47] < 2000) {
                $score_sum_base_one = $score_max_score * 0.8 + $souce_total_base;
            }else{
                $score_sum_base_one = $souce_total_base + $score_max_score;
            }
            $temp_score_oneti = getScoreExd($answer_arr[17],17);

            //行业加分值
            $score_sum_base_addfive = 5;
            //第二次计算基础版得分计算
            $score_sum_base_onescore = $score_sum_base_one + $temp_score_oneti + $score_sum_base_addfive;

            $is_list_score_addsub = 0;
            if ($score_sum_base_onescore <= 80 && $score_sum_base_onescore > 75 && $answer_arr[26] == 2) {
                $is_list_score_addsub = -3;
            } else if ($score_sum_base_onescore <= 90 && $score_sum_base_onescore > 85 && $answer_arr[26] == 1) {
                $is_list_score_addsub = -3;
            } else if ($score_sum_base_onescore <= 85 && $score_sum_base_onescore > 80 && $answer_arr[26] == 2) {
                $is_list_score_addsub = -5;
            } else if ($score_sum_base_onescore <= 95 && $score_sum_base_onescore > 90 && $answer_arr[26] == 1) {
                $is_list_score_addsub = -5;
            } else if ($score_sum_base_onescore <= 90 && $score_sum_base_onescore > 85 && $answer_arr[26] == 2) {
                $is_list_score_addsub = -10;
            }else if ($score_sum_base_onescore <= 100 && $score_sum_base_onescore > 95 && $answer_arr[26] == 1) {
                $is_list_score_addsub = -10;
            }else if ($score_sum_base_onescore <= 95 && $score_sum_base_onescore > 90 && $answer_arr[26] == 2) {
                $is_list_score_addsub = -15;
            }else if ($score_sum_base_onescore <= 105 && $score_sum_base_onescore > 100 && $answer_arr[26] == 1) {
                $is_list_score_addsub = -15;
            }else if ($score_sum_base_onescore <= 100 && $score_sum_base_onescore > 95 && $answer_arr[26] == 2) {
                $is_list_score_addsub = -20;
            }else if ($score_sum_base_onescore > 105 && $answer_arr[26] == 1) {
                $is_list_score_addsub = -20;
            }else if ($score_sum_base_onescore <= 105 && $score_sum_base_onescore > 100 && $answer_arr[26] == 2) {
                $is_list_score_addsub = -25;
            }else if ($score_sum_base_onescore > 105 && $answer_arr[26] == 2) {
                $is_list_score_addsub = -30;
            }
            $score_sum_base_onescore = $score_sum_base_onescore + $is_list_score_addsub;

            //首次算出得分
            $base_one_get_score = 0;
            if($score_sum_base_onescore > 80 && $answer_arr[26] == 2){
                $base_one_get_score = 80;
            }else if ($score_sum_base_onescore > 90 &&  $answer_arr[26] == 1){
                $base_one_get_score = 90;
            }else{
                $base_one_get_score = $score_sum_base_onescore;
            }
            //二次扣分项，再次对总数进行扣减
            $base_again_score_addsub = 0;
            if ($base_one_get_score <= 60) {
                $base_again_score_addsub = 0;
            } else if ($base_one_get_score > 60 && $answer_arr[58] < -2000 && $answer_arr[58] > -5000) {
                $base_again_score_addsub = -5;
            } else if ($base_one_get_score > 60 && $answer_arr[58] <= -5000 && $answer_arr[58] > -10000) {
                $base_again_score_addsub = -10;
            } else if ($base_one_get_score > 60 && $answer_arr[58] <= -10000) {
                $base_again_score_addsub = -10;
            } else if ($base_one_get_score > 60 && $answer_arr[28] < 5) {
                $base_again_score_addsub = -15;
            } else if ($base_one_get_score > 60 && $answer_arr[28] < 10 && $answer_arr[28] >= 5) {
                $base_again_score_addsub = -10;
            } else if ($base_one_get_score > 60 && $answer_arr[28] < 20 && $answer_arr[28] >= 10) {
                $base_again_score_addsub = -5;
            }
            //创造性属性计算
            //每年研发费用占比计算
            $yanfa_prece_one = 0;
            $yanfa_prece_teo = 0;
            $yanfa_prece_three = 0;
            $yanfa_prece_status = 0;
            $profit_prece_status = 0;
            $people_prece_status = 0;
            if ($answer_arr[50] > 0) {
                $yanfa_prece_one = $answer_arr[47] / $answer_arr[50];
            }
            if ($answer_arr[51] > 0) {
                $yanfa_prece_teo = $answer_arr[48] / $answer_arr[51];
            }
            if ($answer_arr[52] > 0) {
                $yanfa_prece_three = $answer_arr[49] / $answer_arr[52];
            }
            if ($yanfa_prece_one > 0.05 || $yanfa_prece_teo > 0.05 || $yanfa_prece_three > 0.05 || ($answer_arr[47] + $answer_arr[48] + $answer_arr[49]) > 6000) {
                $yanfa_prece_status = 1;
            }
            //营收额标准评判
            if ($answer_arr[52] > 0) {
                if ($answer_arr[50] > 30000 || (pow($answer_arr[50] / $answer_arr[52], 3) - 1) > 0.2) {
                    $profit_prece_status = 1;
                }
            }
            //研发角度分析
            if ($answer_arr[46] / $answer_arr[24] > 0.1) {
                $people_prece_status = 1;
            }
            //计算创造性指标1
            $create_index_one = 0;
            $create_index_two = 0;
            if ($answer_arr[34] > 5 && $yanfa_prece_status == 1 && $profit_prece_status == 1 && $people_prece_status == 1) {
                $create_index_one = 1;
            }
            //计算创造性指标2 && ()
            $temp_guojilignxian = 0;
            if ($answer_arr[77] == 2 || $answer_arr[77] == 3) {
                $temp_guojilignxian = 1;
            }
            if ($answer_arr[34] > 50 || $answer_arr[72] == 1 || $answer_arr[66] != 8 || $answer_arr[68] != 11 || $temp_guojilignxian == 1) {
                $create_index_two = 1;
            }
            //判断是否有创造性
            $is_create_index = 0;
            if ($create_index_one == 1 || $create_index_two == 1) {
                $is_create_index = 1;
            }
            $base_again_score_addsub_two = 0;
            if ($is_create_index == 0 && $base_one_get_score > 60 && $base_one_get_score < 80) {
                $base_again_score_addsub_two = -10;
            } else if ($is_create_index == 0 && $base_one_get_score > 80) {
                $base_again_score_addsub_two = -20;
            }
            //基础版最终得分
            $base_score_count_one = $base_one_get_score + $base_again_score_addsub + $base_again_score_addsub_two;

           
            $score_sum = $base_score_count_one;

            //快速评语
            if ($score_sum < 30) {
                //S84
                $summary_preview = "根据测评结果，预计贵司登陆科创板、创业板和其它主板还需要较长时间。建议贵司制定5年规划，在注重营收的前提下，合理配置资源，逐一补足专利、技术、研发等创新单项短板，以创新维度提升，增强融资能力，最终实现上市目标。同时，建议贵司在专利质量、布局和专利侵权风险规避方面下功夫，提高竞争门槛，规避或减小融资或上市前被侵权诉讼的风险。";
            } else if ($score_sum >= 30 && $score_sum < 40) {
                //S85
                $summary_preview = '根据测评结果，预计贵司登陆科创板、创业板和其他主板还需要较长时间。建议贵司制定5年规划，在注重营收的前提下，配置资源，逐一补足专利、技术、研发等创新单项短板，以创新维度提升，增强融资能力，保五争三，争取5年内完成上市。同时，建议贵司在专利质量、布局和侵权风险规避方面下功夫，提高竞争门槛，规避或减小融资或上市前被侵权诉讼的风险。';
            } else if ($score_sum >= 40 && $score_sum < 50) {
                //S86
                $summary_preview = '根据测评结果，预计贵司登陆科创板、创业板和其它主板需要4年左右时间。建议贵司制定4年规划，在注重营收前提下，配置资源，逐一补足专利、技术、研发等创新单项短板，以创新维度提升，增强融资能力，保四争三，争取4年内完成上市。同时，建议贵司在专利质量、布局和侵权风险规避方面下功夫，提高竞争门槛，规避或减小融资或上市前被侵权诉讼的风险。';
            } else if ($score_sum >= 50 && $score_sum < 60) {
                //S87
                $summary_preview = '根据测评结果，预计贵司登陆科创板、创业板和其它主板需要3年左右时间。建议贵司制定3年规划，在注重营收前提下，配置资源，逐一补足专利、技术、研发等创新单项短板，以创新维度提升，增强融资能力，保三争二，争取3年内完成上市。同时，建议贵司在专利质量、布局和侵权风险规避方面下功夫，提高竞争门槛，规避或减小融资或上市前被侵权诉讼的风险。';
            } else if ($score_sum >= 60 && $score_sum < 70) {
                //S87
                $summary_preview = '根据测评结果，预计贵司登陆科创板、创业板和其它主板需要2年左右时间。建议贵司制定2年规划，在注重营收前提下，配置资源，逐一补足专利、技术、研发等创新单项短板，以创新维度提升，增强融资能力，争取2年内完成上市。同时，建议贵司在专利质量、布局和侵权风险规避方面下功夫，提高竞争门槛，规避或减小融资或上市前被侵权诉讼的风险。';
            } else if ($score_sum >= 70) {
                //S88
                $summary_preview = '根据测评结果，预计贵司在创新方面已经基本符合登陆科创板、创业板和其它主板的要求。 建议贵司考虑启动上市计划，聘请券商和高端创新服务机构进场，配置资源，高效补足专利、技术、研发等创新单项短板。 同时，特别提醒贵司要关注技术秘密保护和加强知识产权保护，及专利侵权预警和风险规避，避免由于侵权诉讼而遭遇上市过程拖时、拖累、拖垮、拖死的四拖后果。';
            }
            //$return_data = ['score'=>$score_sum,'summary_preview'=>$summary_preview,'content'=>$result_data];
            // dump($score_sum);die;
            //dump($result_data);die;
            //dump($return_data);die;
            $result_josn = json_encode($result_data,JSON_UNESCAPED_UNICODE);


            $company = $answer_arr[169];

            $company_guimo_arr = ['',"大型企业","中型企业","小型企业","微型企业"];
            $company_guimo = $company_guimo_arr[$answer_arr[18]];

            $company_isshangshi_arr = ['',"已上市","未上市"];
            $company_isshangshi= $company_isshangshi_arr[$answer_arr[26]];

            $company_code = $answer_arr[170];

            $params = db('questions')->where('id',17)->value('params');
            $params = json_decode($params,true);
            $company_isshangshi_arr = $params['selector'];
            $company_lingyu = $company_isshangshi_arr[$answer_arr[17]-1];
            
            //折线图
            $chart1 = $chart2 = [];
            foreach(array_values($score_jc) as $k=>$v){
                $chart1[$k]['label'] = $k+1;
                $chart1[$k]['y'] = $v;
            }
            $score_bz = [4,5,5,2,2,2,3,7,4,8.4,3.2,8.8,10,2,3,3,5.1,2.3,3.1,4.2,5.7,7.2];//标准分值
            foreach($score_bz as $k=>$v){
                $chart2[$k]['label'] = $k+1;
                $chart2[$k]['y'] = $v;
            }
            $chart1_json = json_encode($chart1,JSON_UNESCAPED_UNICODE);
            $chart2_json = json_encode($chart2,JSON_UNESCAPED_UNICODE);
            
            //科创属性
            $kechuang['title'] = '科创属性4+5 指引';
            $kechuang['info'] = [];
            $v1 = ($answer_arr[34]>5)?'是':'否';
            array_push($kechuang['info'],['k'=>'拥有5件或以上自主研发的与核心技术和产品相关的授权发明专利','v'=>$v1]);
            if(($answer_arr[47]/$answer_arr[50]>0.05) || $answer_arr[48]/$answer_arr[51]>0.05 || $answer_arr[49]/$answer_arr[52]>0.05 || ($answer_arr[47]+$answer_arr[48]+$answer_arr[49])>6000){
                $v2 = '是';
            }else{
                $v2 = '否';
            }
            array_push($kechuang['info'],['k'=>'近三年研发投入占营业收入比例5%以上或近三年研发投入累计6000万以上','v'=>$v2]);
            
            if($answer_arr[50]>3000 || pow($answer_arr[50]/$answer_arr[53],1/3)>20){
                $v3 = '是';
            }else{
                $v3 = '否';
            }
            array_push($kechuang['info'],['k'=>'最近一年营收总额达到3亿或三年复合增长率达到20％','v'=>$v3]);
            $v4 =($answer_arr[46]/$answer_arr[24] > 10)?'是':'否';
            array_push($kechuang['info'],['k'=>'研发人员占全员职工比例达到或超过10%','v'=>$v4]);
            $v5 = ($v1 == '是' && $v2 == '是' && $v3 == '是' && $v4 == '是')?'同时满足':'没有同时满足';
            array_unshift($kechuang['info'],['k'=>'第一套指引','v'=>$v5]);
           
            $v6 = ($answer_arr[33]>50)?'是':'否';
            $v7 = ($answer_arr[72] == 2 || $answer_arr[72] == '否')?'否':'是';
            $v8 = ($answer_arr[66] == 0 || $answer_arr[66] == '以上都无')?'否':'是';
            $v9 = ($answer_arr[77] == 2 || $answer_arr[77] == 3)?'是':'否';
            $v10 = ($answer_arr[68] == 11)?'否':'是';
            $v11 = ($v6 == '是' || $v7 == '是' || $v8 == '是' || $v9 == '是' || $v10 == '是')?'至少满足一项':'都不满足';
            $kechuang['info'][5] = ['k'=>'第二套指引','v'=>$v11];
            $kechuang['info'][6] = ['k'=>'拥有50件或以上自主研发的与核心技术和产品相关的授权发明专利','v'=>$v6];
            $kechuang['info'][7] = ['k'=>'是否有望替代西方技术产品','v'=>$v7];
            $kechuang['info'][8] = ['k'=>'是否承担国家重大科技专项','v'=>$v8];
            $kechuang['info'][9] = ['k'=>'是否拥有国家颁发的技术/产品国际领先或国家战略认证','v'=>$v9];
            $kechuang['info'][10] = ['k'=>'是否获得国家级别科技奖励','v'=>$v10];
            
            $kechuang['result'] = ($v5 == '同时满足' || $v11 == '至少满足一项')?'有科创属性':'没有科创属性';
            
            $kechuang = json_encode($kechuang,JSON_UNESCAPED_UNICODE);
            $flag = db::name('answer')->where('a_id',$a_id)->update(['is_baogao'=>1,'score'=>$score_sum,'summary_preview'=>$summary_preview,'result_josn'=>$result_josn,'souce_total_base'=>$souce_total_base,'update_time'=>time(),'company'=>$company,'company_guimo'=>$company_guimo,'company_isshangshi'=>$company_isshangshi,'company_code'=>$company_code,'company_lingyu'=>$company_lingyu,'chart1_json'=>$chart1_json,'chart2_json'=>$chart2_json,'kechuang'=>$kechuang]);
            if($flag){
                return true;
            }else{
                return false;
            }

        }catch(\Exception $e){
            //  echo $e->getMessage(); // 返回自定义的异常信息
            setLog('wenjuan',$e->getMessage());die;
            //Log::error('失败原因:123'.$e->getMessage() );
            //var_dump(db::name('questions')->getLastSql());
        }

    }

}